package com.elinkway.infinitemovies.adapter;

import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentStatePagerAdapter;

import com.elinkway.infinitemovies.bean.LiveClassifyInfos;
import com.elinkway.infinitemovies.bean.LiveInfos;
import com.elinkway.infinitemovies.ui.fragment.LiveInfoFragment;

/**
 * 管理直播Tab Fragment 的Adapter
 * @author zhangshuo
 *
 */
public class LiveFragmentStateAdapter extends FragmentStatePagerAdapter {

	private LiveInfos mDataset;
	private Context context;
	
    public LiveFragmentStateAdapter(FragmentManager fm, Context context, LiveInfos infos) {
        super(fm);
        this.context = context;
        mDataset = infos;
    }

    @Override
	public CharSequence getPageTitle(int position) {
		return mDataset.getAllInfos().get(position).getCheineseName();
	}

	@Override
    public Fragment getItem(int position) {
		Fragment frag = Fragment.instantiate(context, LiveInfoFragment.class.getName());
		Bundle bundle = new Bundle();
		LiveClassifyInfos classifyInfo = mDataset.getAllInfos().get(position);
		bundle.putString(LiveInfoFragment.ARGUMENT_CATEGORY_CHINESE_NAME, classifyInfo.getCheineseName());
		bundle.putString(LiveInfoFragment.ARGUMENT_IDENTIFIER, classifyInfo.getIdentifier());
		frag.setArguments(bundle);
        return frag;
    }

    @Override
    public int getCount() {
        return mDataset.getAllInfos().size();
    }

}
